package com.neusoft.mapper;

import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Delete;
import com.neusoft.po.Comment;

@Mapper
public interface CommentMapper {

	public List<Comment> listCommentByBusinessId(@Param("businessId") Integer businessId);

	@Select("select * from comment where userId=#{userId} order by createTime desc")
	public List<Comment> listCommentByUserId(@Param("userId") String userId);

	@Select("select * from comment where orderId=#{orderId}")
	public Comment getCommentByOrderId(@Param("orderId") Integer orderId);

	@Select("select avg(rating) from comment where businessId=#{businessId}")
	public Double getAverageRatingByBusinessId(@Param("businessId") Integer businessId);

	@Insert("insert into comment(userId,businessId,orderId,commentContent,rating,isAnonymous,createTime,updateTime) values(#{userId},#{businessId},#{orderId},#{commentContent},#{rating},#{isAnonymous},#{createTime},#{updateTime})")
	public int saveComment(Comment comment);

	@Update("update comment set commentContent=#{commentContent},rating=#{rating},isAnonymous=#{isAnonymous},updateTime=#{updateTime} where commentId=#{commentId}")
	public int updateComment(@Param("commentId") Integer commentId, @Param("commentContent") String commentContent,
			@Param("rating") Integer rating, @Param("isAnonymous") Boolean isAnonymous,
			@Param("updateTime") String updateTime);

	@Delete("delete from comment where commentId=#{commentId}")
	public int deleteComment(@Param("commentId") Integer commentId);
}